package com.lqwu.manymanythumb.controller;

import com.lqwu.manymanythumb.common.BaseResponse;
import com.lqwu.manymanythumb.common.ResultUtils;
import com.lqwu.manymanythumb.model.entry.Blog;
import com.lqwu.manymanythumb.model.vo.BlogVo;
import com.lqwu.manymanythumb.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("blog")
public class BlogController {

    @Resource
    private BlogService blogService;

    /**
     * 获取博客详情
     * @param blogId
     * @param request
     * @return
     */
    @GetMapping("/get")
    public BaseResponse<BlogVo> get(long blogId, HttpServletRequest request){
        BlogVo blogVoById = blogService.getBlogVoById(blogId, request);
        return ResultUtils.success(blogVoById);
    }

    /**
     * 获取博客列表
     * @param request
     * @return
     */
    @GetMapping("/list")
    public BaseResponse<List<BlogVo>> list(HttpServletRequest request){
        List<Blog> blogList = blogService.list();
        List<BlogVo> blogVoList = blogService.getBlogVoList(blogList, request);
        return ResultUtils.success(blogVoList);
    }
}
